package cn.iscorpio.ssm.web;

import java.text.MessageFormat;

/**
 * @author chenkx
 * @date 2018-05-04.
 */
public enum RestCode {
    OK(0, "OK"),
    SERVER_ERROR(1000, "服务器请求异常"),
    DEGRADE_ERROR(1001, "服务降级，请求失败"),
    PARAMETER_ERROR(1002, "参数不合法"),
    PARAMETER_NOT_NULL(1003, "参数不能为空"),
    PARAMETER_TYPE_ERROR(1004, "参数类型异常"),
    PARAMETER_CAST_ERROR(1005, "参数转换异常"),
    PARAMETER_EMPTY_ERROR(1006, "参数转换异常"),
    MEDIA_TYPE_NOT_SUPPORT(1007, "不支持的媒体类型"),
    NULL_POINTER_ERROR(1008, "空指针异常"),
    METHOD_NOT_SUPPORT(1009, "不支持的请求类型"),
    CLASS_CAST_ERROR(1010, "类型转换异常"),
    NUMBER_FORMAT_ERROR(1011, "数字转化异常"),
    EXTEND_JSON_ERROR(1012, "JSON格式异常"),
    REPEAT_SUBMIT_EXCEPTION(1013, "请勿重复操作"),
    BEAN_EMPTY_PROPERTY_ERROR(1014, "实体转换异常");

    public final int code;
    public String msg;

    private RestCode(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public int getCode() {
        return this.code;
    }

    public String getMessage(Object... param) {
        return param.length == 0 ? this.msg : MessageFormat.format(this.msg, param);
    }

    public void setMessage(String msg) {
        this.msg = msg;
    }

    public static RestCode getByCode(int code) {
        RestCode[] values = values();
        RestCode[] var2 = values;
        int var3 = values.length;

        for(int var4 = 0; var4 < var3; ++var4) {
            RestCode value = var2[var4];
            if (value.getCode() == code) {
                return value;
            }
        }

        return null;
    }
}
